package com.bkbw.live.battle.test;
import java.util.concurrent.TimeUnit;
import akka.actor.Cancellable;
import akka.actor.UntypedActor;
import akka.util.Duration;

public class Actor1 extends UntypedActor{
	private Cancellable cancel;
	private long last;
	private long count = 0;
	@Override
	public void onReceive(Object arg0) throws Exception {
		System.out.println(arg0);
		if("start".equals(arg0)){
			cancel = this.getContext().system().scheduler().schedule(Duration.Zero(),Duration.create(50, TimeUnit.MILLISECONDS),new Runnable() {
				@Override
				public void run() {
					update();
				}
			} );
		}
		if("loop".equals(arg0)){
			 update();
		}
		if("stop".equals(arg0)){
			cancel.cancel();
		}
	}
	
	private void update(){
		
		count ++;
		if(count%10==0){
			long now = System.currentTimeMillis();
			System.out.println(now - last);
			last = now;
		}
		
	}
}